unit Test;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TfrmTest = class(TForm)
    RemoveDir_Btn: TButton;
    WinVer_Btn: TButton;
    WinSupportedByApp_Btn: TButton;
    WinEditionSupportedByApp_Btn: TButton;
    GetAppDir_Btn: TButton;
    GetFileSize_Btn: TButton;
    GetSelfVersion_Btn: TButton;
    MatchingToken_Btn: TButton;
    CreateDirEx_Btn: TButton;
    RepeatStr_Btn: TButton;
    ValidateFileName_Btn: TButton;
    TColorToHTML_Btn: TButton;
    HTMLToTColor_Btn: TButton;
    GetByte_Btn: TButton;
    TColorToRGB_Btn: TButton;
    RGBToTColor_Btn: TButton;
    GetTokBetween_Btn: TButton;
    procedure RemoveDir_BtnClick(Sender: TObject);
    procedure WinVer_BtnClick(Sender: TObject);
    procedure WinSupportedByApp_BtnClick(Sender: TObject);
    procedure WinEditionSupportedByApp_BtnClick(Sender: TObject);
    procedure GetAppDir_BtnClick(Sender: TObject);
    procedure GetFileSize_BtnClick(Sender: TObject);
    procedure GetSelfVersion_BtnClick(Sender: TObject);
    procedure MatchingToken_BtnClick(Sender: TObject);
    procedure CreateDirEx_BtnClick(Sender: TObject);
    procedure RepeatStr_BtnClick(Sender: TObject);
    procedure ValidateFileName_BtnClick(Sender: TObject);
    procedure TColorToHTML_BtnClick(Sender: TObject);
    procedure HTMLToTColor_BtnClick(Sender: TObject);
    procedure GetByte_BtnClick(Sender: TObject);
    procedure TColorToRGB_BtnClick(Sender: TObject);
    procedure RGBToTColor_BtnClick(Sender: TObject);
    procedure GetTokBetween_BtnClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmTest: TfrmTest;

implementation

uses SysUtilsEx;

{$R *.dfm}

procedure TfrmTest.WinEditionSupportedByApp_BtnClick(Sender: TObject);
begin
  ShowMessage(BoolToStr(IsCurrentWinEditionSupported([weProfessional, weEnterprise]), True));
end;

procedure TfrmTest.GetFileSize_BtnClick(Sender: TObject);
begin
  ShowMessage(FormatSize(GetFileSize(Application.ExeName)));
end;

procedure TfrmTest.GetSelfVersion_BtnClick(Sender: TObject);
begin
  ShowMessage(GetSelfVersion);
end;

procedure TfrmTest.GetTokBetween_BtnClick(Sender: TObject);
  const
    STR_S = 'test string that has separator1 and the text between them and separator2 and the end of text';
begin
  ShowMessage(STR_S + sLineBreak +
    QuotedStr(GetTokenBetweenSeparators(STR_S, 'separator1', 'separator2')));
end;

procedure TfrmTest.HTMLToTColor_BtnClick(Sender: TObject);
begin
  ShowMessage(IntToStr(clRed) + ' = ' + IntToStr(HTMLToTColor('#FF0000')));
end;

procedure TfrmTest.MatchingToken_BtnClick(Sender: TObject);
  var
    iRes : Cardinal;
    sText, sSubStr : String;
begin
  sText := '123 456 789 000 001 002 003 004 005';
  sSubStr := '0';
  If Not (InputQuery('MatchingToken', 'Text', sText) And
          InputQuery('MatchingToken', 'Substring', sSubStr)) Then Exit;

  iRes := MatchingToken(sText, sSubStr, 0, ' ');
  ShowMessage('Num of tokens with "0": ' + IntToStr(iRes));

  iRes := MatchingToken(sText, sSubStr, 1, ' ');
  ShowMessage('Position of first found token with "0": ' + IntToStr(iRes));
end;

procedure TfrmTest.TColorToRGB_BtnClick(Sender: TObject);
begin
  ShowMessage(IntToHex(TColorToRGB(RGB($AA, $BB, $CC)), 6));
end;

procedure TfrmTest.CreateDirEx_BtnClick(Sender: TObject);
begin
  ShowMessage(BoolToStr(CreateDirEx(InputBox('CreateDirEx', 'Path', 'D:\test\lol')), True));
end;

procedure TfrmTest.GetAppDir_BtnClick(Sender: TObject);
begin
  ShowMessage(GetAppDir);
end;

procedure TfrmTest.GetByte_BtnClick(Sender: TObject);
  const
    INT_VALUE = $0E000384;
  var
    S : String;
begin
  S := IntToStr(GetByte(INT_VALUE, 4)) + '.' +
       IntToStr(GetByte(INT_VALUE, 3)) + '.' +
       IntToStr(LoWord(INT_VALUE));
  ShowMessage('14.0.900 | ' + S);
end;

procedure TfrmTest.RemoveDir_BtnClick(Sender: TObject);
begin
  ShowMessage(BoolToStr(RemoveDir(InputBox('Test', 'RemoveDir', 'D:\dir1')), True));
end;

procedure TfrmTest.RepeatStr_BtnClick(Sender: TObject);
begin
  Randomize;
  ShowMessage(RepeatStr('string', Random(10)));
  Randomize;
  ShowMessage(RepeatStr('string', Random(10), '|'));
end;

procedure TfrmTest.RGBToTColor_BtnClick(Sender: TObject);
begin
  ShowMessage(IntToHex(RGBToTColor($AABBCC), 6));
end;

procedure TfrmTest.TColorToHTML_BtnClick(Sender: TObject);
begin
  ShowMessage(TColorToHTML(clRed));
end;

procedure TfrmTest.ValidateFileName_BtnClick(Sender: TObject);
begin
  ShowMessage(ValidateFileName('1:234567890:~!@#$%^&*()_+\|/ABCDEF', True));
end;

procedure TfrmTest.WinSupportedByApp_BtnClick(Sender: TObject);
begin
  ShowMessage(BoolToStr(IsCurrentWinVersionSupported([wvSe7en, wvVista, wvXP]), True));
end;

procedure TfrmTest.WinVer_BtnClick(Sender: TObject);
  var
    WV : TWindowsVersion;
begin
  ShowMessage(BoolToStr(GetWindowsVersion(WV), True));
  With WV do
    ShowMessage(ToString + #13#10 + 'Service Pack Version: ' +
                IntToStr(ServicePack.Major) + '.' + IntToStr(ServicePack.Minor) + #13#10 +
                'Additional Info: ' + CSDVersion);
end;

end.
